<template>
  <div class="login-container">
    <div class="container">
      <video class="video-background" preload="auto" loop autoplay muted src="https://slwl-admin.itheima.net/static/media/video.3cf57b17.mp4" />
    </div>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <img src="@/assets/assets/logo.png">
      </div>
      <el-form ref="ruleForm" :model="loginForm" :rules="loginRules">
        <el-form-item prop="account">
          <el-input v-model="loginForm.account" prefix-icon="el-icon-user-solid" type="text" autocomplete="off" @keydown.enter.native="submitForm" />
        </el-form-item>
        <el-form-item prop="password">
          <el-input v-model="loginForm.password" prefix-icon="el-icon-unlock" type="password" autocomplete="off" show-password @keydown.enter.native="submitForm" />
        </el-form-item>
        <el-form-item prop="code">
          <div>
            <el-input v-model="loginForm.code" prefix-icon="el-icon-s-goods" type="text" autocomplete="off" @keydown.enter.native="submitForm">
              <template #suffix>
                <div class="codeImg">
                  <img ref="vcImg" src="" alt="验证码" @click="codeImg">
                </div>
              </template>
            </el-input>
          </div>
        </el-form-item>
        <el-form-item>
          <el-button class="btn" @click="submitForm">登录</el-button>
        </el-form-item>
      </el-form>
    </el-card>

  </div>
</template>

<script>
// import { captcha } from '@/api/user'
export default {
  name: 'Login',
  data() {
    return {
      loginForm: {
        //  变量名 不要直接起  看接口文档
        account: 'demo',
        password: '888itcast.CN764%...',
        code: '',
        key: ''
      },
      loginRules: {
        account: [{ required: true, message: '不能为空', trigger: 'blur' }],
        password: [{ required: true, message: '不能为空', trigger: 'blur' }],
        code: [{ required: true, message: '不能为空', trigger: 'blur' }]
      },
      imgUrl: ''
    }
  },
  async created() {
    this.$nextTick(() => {
      this.codeImg()
    })
  },
  methods: {
    async submitForm() {
      await this.$refs.ruleForm.validate()
      await this.$store.dispatch('user/login', this.loginForm)
      this.$message.success('登录成功')
      // await login(this.loginForm)
      setTimeout(() => {
        this.$router.push('/')
      }, 1500)
    },
    async codeImg() {
      this.loginForm.key = '99C6390B12131B388D048793169414444884' + Math.floor(Math.random() * 10)
      this.$refs.vcImg.src = 'https://slwl-geteway.itheima.net/manager/captcha?' + `key=${this.loginForm.key}`
    }
  }
}
</script>
<style lang="scss">
.login-container {
  position: relative;
  height: 100%;
  overflow: hidden;
  .video-background{
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
  .box-card{
    position: absolute;
    width: 450px;
    height: 490px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 36px 40px;
    background: #fff;
    border-radius: 10px;
    text-align: center;
  .el-card__header{
    text-align: center;
    margin-bottom: 28px;
    padding:0px 0px;
    border-bottom: none;
    img{
      height: 54px;
    }
    }
    .btn{
      background-color: #e15536;
      color: #fff;
      font-size: 18px;
      font-weight: 700;
      width: 100%;
    }
    .el-form-item__label{
      line-height: 40px;
    }
    .codeImg{
      position: relative;
      img{
        position: absolute;
        right: 10px;
        top: 5px;
        display: inline-block;
        height: 32px;
        width: 71px;
        cursor: pointer;
        margin-left: 10px;
      }
    }
  }
}
</style>
